//
//  CBCChannelCell.m
//  CBCChannelControl
//
//  Created by 李雷川 on 2019/6/30.
//  Copyright © 2019 李雷川. All rights reserved.
//

#import "CBCChannelCell.h"
#import "CBCChannelDef.h"
#import <Masonry/Masonry.h>
@implementation CBCChannelCell
-(instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self initUI];
        self.layer.cornerRadius = 12;
        self.layer.masksToBounds = YES;
        self.layer.borderColor = CBCChannelItemColor.CGColor;
        self.layer.borderWidth = 1;
    }
    return self;
}

-(void)setSelected:(BOOL)selected{
    if(selected){
        self.backgroundColor = CBCChannelSelectBackgroundColor;
        self.titleLabel.textColor = [UIColor whiteColor];
        self.layer.borderColor = CBCChannelSelectBackgroundColor.CGColor;
    }else{
        self.backgroundColor = [UIColor clearColor];
        self.titleLabel.textColor = CBCChannelItemColor;
        self.layer.borderColor = CBCChannelItemColor.CGColor;
    }
}

-(void)initUI{
    [self addSubview:self.titleLabel];
    [self addSubview:self.imageView];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_offset(6);
        make.top.mas_offset(-6);
    }];
    
    
}

-(UILabel *)titleLabel{
    if(_titleLabel == nil){
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = CBCChannelItemColor;
  
    }
    return _titleLabel;
}

-(UIImageView *)imageView{
    if (_imageView == nil) {
        UIImage *image = CBCChanelImage(@"delete");
        _imageView = [[UIImageView alloc]initWithImage:image];
    }
    return _imageView;
}
@end
